import request from '@/utils/request'

export function login(data) {
  return request({
    url: '/auth/login',
    method: 'post',
    data
  })
}

export function getInfo() {
  return request({
    url: '/auth/info',
    method: 'get'
  })
}

export function logout() {
  return request({
    url: '/auth/logout',
    method: 'post'
  })
}

export function getUsers(data, offset, limit) {
  return request({
    url: '/user',
    method: 'get',
    params: {
      name: data.name,
      workId: data.workId,
      status: data.status,
      offset: offset,
      limit: limit
    }
  })
}

export function getUserList() {
  return request({
    url: '/user/list',
    method: 'get'
  })
}

export function addUser(data) {
  return request({
    url: '/user',
    method: 'post',
    data
  })
}

export function modifyUser(id, data) {
  return request({
    url: `/user/${id}`,
    method: 'put',
    data
  })
}

export function modifyMine(data) {
  return request({
    url: `/user/mine`,
    method: 'put',
    data
  })
}

export function modifyStatus(id, status) {
  return request({
    url: `/user/status/${id}?status=${status}`,
    method: 'put'
  })
}
export function modifyAvatar(fileId) {
  return request({
    url: `/user/avatar/${fileId}`,
    method: 'put'
  })
}

export function modifyPassword(password) {
  return request({
    url: `/auth/password`,
    method: 'post',
    headers: {'Content-Type':'application/x-www-form-urlencoded'},
    params: {
      oldPassword: password.oldPassword,
      newPassword: password.newPassword
    }
  })
}
